package com.zhuxiaomei.mapper;

import com.zhuxiaomei.annotation.AutoFill;
import com.zhuxiaomei.entity.restaurant.RestaurantDish;
import com.zhuxiaomei.enumeration.OperationType;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;
import tk.mybatis.mapper.common.Mapper;

import java.util.List;

/**
 * @author hxm
 * @date 2024/11/11 17:43
 * @description
 */
public interface RestaurantDishMapper extends Mapper<RestaurantDish> {
    @Select("select id,dish_name,price,dish_image,description,status,category_id from restaurant_dishes where status = #{status} and is_deleted = 0")
    List<RestaurantDish> selectDishByStatus(@Param("status") String status);

    /**
     * 根据id批量修改status
     * @param status
     * @param idList
     * @return
     */
    @AutoFill(OperationType.UPDATE)
    Integer updateStatusByBatchId(@Param("status") Byte status, @Param("idList") List<Long> idList);

    @AutoFill(OperationType.INSERT)
    Integer insertRestaurantDish(RestaurantDish restaurantDish);

    @Select("select id,dish_name,price,dish_image,description,status,category_id from restaurant_dishes where id = #{id}")
    RestaurantDish selectOneById(@Param("id") Long id);

    @AutoFill(OperationType.UPDATE)
    int updateRestaurantDishById(RestaurantDish restaurantDish);

    List<RestaurantDish> selectRestaurantDishesByBatchIds(@Param("idList") List<Long> idList);

    List<RestaurantDish> selectRestaurantDishesByCategoryId(@Param("categoryId") Long categoryId);

    @Select("select id from restaurant_dishes where category_id = #{categoryId} and status = 1")
    List<Long> selectDishOnsaleByCategoryId(@Param("categoryId") Long categoryId);

    @Select("select id from restaurant_dishes where category_id = #{categoryId} and status = 0")
    List<Long> selectDishOnNosaleByCategoryId(Long categoryId);


    void deleteByBathIds(@Param("idList")List<Long> idList);
}
